package org.xxpay.pay.channel.payeasepay.demo;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.xxpay.pay.channel.payeasepay.demo.CFCA.MerchantX509Cert;

import javax.ws.rs.core.MultivaluedMap;

/**
 * 
 * 代付提交接口
 * 
 * 
 * 
 */
public class Submit {
	/**
	 * @param args
	 * @throws Exception
	 */
	// 银行卡列列表url
	private static final String SINGLE_CHECK_URL = "https://paytest.yizhifubj.com/merchant/virement/mer_payment_submit_utf8.jsp";

	public static void main(String[] args) throws Exception {
		String XML = Submit(); // 
		
		System.out.println("-----------------------------------------------------"); 
		System.out.println(XML); // 获得接口返回xml数据
		

	}

	

	public static String Submit() throws Exception {
		System.setProperty("https.protocols", "TLSv1.2,TLSv1.1,SSLv3");
		Client cc = Client.create();
		WebResource rr = cc.resource(SINGLE_CHECK_URL);

		MultivaluedMap queryParams = new MultivaluedMapImpl();
		
		String v_mid = "7606";//商户号
		String v_datas ="1|0.1|7606-20181213-000003$6214850116825883|丁志伟|招商银行|北京市|北京市|0.1|T01201812131144252880005|308584000013";
		String v_data = java.net.URLEncoder.encode(v_datas, "UTF-8");
		
		String v_nama = "7606";
		String data = java.net.URLEncoder.encode(v_nama, "UTF-8");
		System.out.println("name:"+data);
		System.out.println(v_data);
		String v_version ="1.0";
		String str=v_mid+v_data;

		//CFCA签名
		String pfxFile = "D:/certificate/payease/cfca_private.pfx";//私钥文件
	    String pfxPassword = "lh121121";
	    String aliasPassword = "lh121121";
	    String aliasName = "{3dfcbb2d-bb3d-4350-9010-33de8cdb076c}";
	    String sign = MerchantX509Cert.sign(str, pfxFile, aliasName, pfxPassword, aliasPassword);
		System.out.println(sign) ;
		System.out.println("--------------------------------------------------") ;
		queryParams.add("v_mid", v_mid); 
		queryParams.add("v_data", java.net.URLEncoder.encode(v_datas, "GBK"));
		queryParams.add("v_version", v_version);
		queryParams.add("v_mac", sign);
		String ret = rr.queryParams(queryParams).post(String.class);
		return ret;
		
	}

}
